import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @ClassName: ChatClient
 * @DESCRIPT: TODO
 * @AUTHOR: lemontree
 * @DATA: 2020/8/28 4:00 PM
 **/
public class ChatClient {
    int port = 9743;
    Socket socket;

    public static void main(String[] args){
        new ChatClient();
    }

    public ChatClient(){
        try {
            socket = new Socket("152.136.192.60",port);
//            socket = new Socket("127.0.01",port);


            ChatClientThread chatClientThread = new ChatClientThread();
            Thread thread = new Thread(chatClientThread);
            thread.start();

            BufferedReader br = new BufferedReader(new InputStreamReader(socket
                    .getInputStream()));
            String msg1;
            while ((msg1 = br.readLine()) != null) {
                System.out.println(msg1);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    class ChatClientThread implements Runnable{


        public void run() {
            try {

                BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
                PrintWriter pw = new PrintWriter(socket.getOutputStream(), true);
                String msg2;

                while (true) {

                    msg2 = re.readLine();
                    pw.println(msg2);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
